/*
* Copyright 2004-2010 mb_sx@hotmail.com
* All Rights Reserved.
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Outlook = Microsoft.Office.Interop.Outlook;

namespace DeskNotes
{
    public partial class SynchronizationConflictDlg : Form
    {
        public enum Result { KeepDeskNote, KeepOutlook, Merge, Cancel, SyncAll, SyncOne, OutlookMissing};
        private Result result;
        private int fullHeight;
        private Note note;
        internal DateTime outlookModificationTime;

        public SynchronizationConflictDlg()
        {
            InitializeComponent();
        }

        public SynchronizationConflictDlg(Note note, DateTime outlookModificationTime)
        {
            InitializeComponent();
            
            fullHeight = this.Height;
            //Change Height of form just under Details button
            Size cSize = new Size(ClientSize.Width, this.btnDetails.Bounds.Bottom + 5);
            this.ClientSize = cSize;
            this.note = note;
            this.outlookModificationTime = outlookModificationTime;
        }

        new public SynchronizationConflictDlg.Result ShowDialog(IWin32Window owner)
        {

            this.lblDesknoteTime.Text = note.LastModificationTime.ToShortDateString() 
                + ", " + note.LastModificationTime.ToShortTimeString();
            this.lblOutlookTime.Text = outlookModificationTime.ToShortDateString() 
                + ", " + outlookModificationTime.ToShortTimeString();

           base.ShowDialog(owner);
           return result;

       } 

        private void btnDetails_Click(object sender, EventArgs e)
        {
            if (btnDetails.Checked)
            {
                this.Height = fullHeight;
                txtDeskNote.Rtf = note.Text;
                txtDeskNote.BackColor = note.BackgroundColor;
                try{
                    Outlook.NoteItem n = note.OutlookNoteItem;
                    txtOutlook.Font = Properties.Settings.Default.Font;
                    txtOutlook.BackColor = note.BackgroundColor;
                    txtOutlook.ForeColor = Properties.Settings.Default.TextColor;
                    txtOutlook.Text = n.Body;
                } catch (Exception ex){
                    txtOutlook.Text = Resources.AppResource.OutlookError + ex.Message;
                }
            }
            else
            {
                //Change Height of form just under Details button
                Size cSize = new Size(ClientSize.Width, this.btnDetails.Bounds.Bottom + 5);
                this.ClientSize = cSize;

            }
        }

        private void btnDeskNote_Click(object sender, EventArgs e)
        {
            result = Result.KeepDeskNote;
            this.Close();
        }

        private void btnOutlook_Click(object sender, EventArgs e)
        {
            result = Result.KeepOutlook;
            this.Close();
        }

        private void btnMerge_Click(object sender, EventArgs e)
        {
            result = Result.Merge;
            this.Close();
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            result = Result.Cancel;
            //this.Close();

        }

        /// <summary>
        /// Displays Outlook Note.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lblOutlookText_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            try
            {
                Outlook.NoteItem n = note.OutlookNoteItem;
                n.Display(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, Resources.AppResource.APP_TITLE, Resources.AppResource.OutlookError + ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

    }
}